package com.cn.kgc.thymeleaf.controller;

import com.cn.kgc.thymeleaf.entity.Bill;
import com.cn.kgc.thymeleaf.service.BillService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author love
 */
@Controller
@RequestMapping("bill")
@Api(value = "BillController",description = "商品控制器")
public class BillController {

    @Autowired
    private BillService billService;

    private int pageIndex=1;
    private int pageSize=5;

    @GetMapping("/find/{index}/{size}")
    @ApiOperation(notes = "查询方法",value = "find")
    public String find(Bill bill, Model model,@PathVariable Integer index,@PathVariable Integer size){
        if(index!=null){
            pageIndex=index;
        }
        if(size!=null){
            pageSize=size;
        }
        //设置分页
        PageHelper.startPage(pageIndex,pageSize);
        Map<String,Object> param=new HashMap<>();
        List<Bill> list=billService.findByMap(param);
        PageInfo<Bill> info=new PageInfo<>(list);
        model.addAttribute("info",info);
        return "index";
    }

    @PostMapping("/add")
    public String add(Bill bill){
        return "add";
    }

    @GetMapping("/delete/{code}")
    public String delete(@PathVariable String code){
        return "index";
    }

    @GetMapping("/show/{code}")
    public String show(@PathVariable String code){
        return "show";
    }

    @PutMapping("/update")
    public String update(Bill bill){
        return "index";
    }

}
